home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / F123_DEV.lha / FAME_ASM.lha / FAMEDoor_ASM / include / FAMEEasyDoorStartup.i < prev    next >
Text File  |  1996-03-25  |  11KB  |  412 lines

  1.  
  2. ; FAME EasyDoorStartup.i
  3. ;
  4. ; Asm door examples by BLOODROCK/tRSi © 1996 Oliver Lange
  5.  
  6.     IFND    EXEC_EXEC_LIB_I
  7.     INCLUDE    "Exec/Exec_lib.i"
  8.     ENDC
  9.  
  10.     IFND    DOS_DOS_LIB_I
  11.     INCLUDE    "Dos/Dos_lib.i"
  12.     ENDC
  13.  
  14.     IFND    EXEC_MEMORY_I
  15.     INCLUDE    "Exec/Memory.i"
  16.     ENDC
  17.  
  18.     IFND    DOS_DOSEXTENS_I
  19.     INCLUDE    "Dos/DosExtens.i"
  20.     ENDC
  21.  
  22.     IFND    FAME_FAME_I
  23.     INCLUDE "FAME/FAME.i"
  24.     ENDC
  25.  
  26. MinKickVer    EQU    37        ; The minimum OS version number needed
  27.  
  28. send    Macro
  29.         IFGT    128-\1            ; This routine checks the
  30.         moveq   #\1,d0            ; ReturnCode itself.
  31.         bsr     SendDoorCommand        ; If an error occured, the
  32.         ELSE                ; door shuts down with an
  33.         move.l  #\1,d0            ; error text as "ByeMessage".
  34.         bsr     SendDoorCommand
  35.         ENDC
  36.     EndM
  37.  
  38. ;-----------------------------------------------------------------------------
  39.  
  40. EASY_Start:
  41.     move.l    4.w,a6
  42.     cmp.w    #MinKickVer,LIB_VERSION(a6)    ; Must be at least V37
  43.     bhs.s    EASY_KickVersionOK        ; (OS 2.04) -which SysOp
  44. EASY_Fatal:                    ; hasn't got it ?
  45.     moveq    #RETURN_FAIL,d0
  46.     rts
  47.  
  48. EASY_KickVersionOK:               ; This part gets some memory
  49.     movem.l    d0/a0,-(sp)           ; for our data segment. This
  50.     move.l    EASY_MyDataSize(pc),d0       ; is making the door code
  51.     move.l    #MEMF_CLEAR!MEMF_PUBLIC,d1 ; reentrant. There is no fixed
  52.     jsr    _LVOAllocVec(a6)       ; data area, so the door can be
  53.     tst.l    d0               ; load resident, saving memory
  54.     bne.s    EASY_StartupMemOK       ; when running the door more
  55.     movem.l    (sp)+,d0/a0           ; than once at a time (it also
  56.     bra.s    EASY_Fatal           ; reduces door loading time).
  57.                        ; Beginners, remember: using
  58.                        ; AllocVec() instead of AllocMem()
  59.                        ; eliminates possible error sources!
  60. EASY_StartupMemOK:
  61.     move.l    d0,a5
  62.     move.l    a6,AbsExecBase(a5)    ; Faster then..
  63.     move.b    #RETURN_FAIL,ReturnCode(a5)
  64.     sub.l    a1,a1
  65.     jsr    _LVOFindTask(a6)    ; Get our Process structure
  66.     move.l    d0,OwnTask(a5)
  67.     move.l    d0,a3
  68.     tst.l    pr_CLI(a3)        ; Started from WorkBench ?
  69.     bne.s    EASY_StartOK
  70.  
  71.     movem.l    (sp)+,d0/a0        ; No longer needed..
  72.     lea    pr_MsgPort(a3),a0
  73.     jsr    _LVOWaitPort(a6)    ; Wait for the WorkBench message
  74.     lea    pr_MsgPort(a3),a0
  75.     jsr    _LVOGetMsg(a6)
  76.     move.l    d0,d7
  77.     jsr    _LVOForbid(a6)
  78.     move.l    d7,a1                   ; Reply the WorkBench message
  79.     jsr    _LVOReplyMsg(a6)    ; and exit (door must be started
  80.     bra.w    EASY_Finish        ; from FAME).
  81.  
  82. ; ----------------------------------------------------------------------------
  83.  
  84. EASY_StartOK:
  85.     lea    DosName(pc),a1
  86.     moveq    #MinKickVer,d0        ; V37
  87.     jsr    _LVOOpenLibrary(a6)
  88.     move.l    d0,DOSBase(a5)
  89.     beq.w    EASY_Finish
  90.  
  91.     lea    FAMEName(pc),a1
  92.     moveq    #FAMELibVersion,d0
  93.     jsr    _LVOOpenLibrary(a6)
  94.     move.l    d0,FAMEBase(a5)
  95.     beq.w    EASY_Finish
  96.  
  97.     move.l    d0,a6
  98.     moveq    #FOBJ_FAMEDoorMsg,d0
  99.     jsr    _LVOFAMEAllocObject(a6)        ; allocate our DoorMessage
  100.     move.l    d0,DoorMessage(a5)
  101.     beq.w    EASY_Finish
  102.  
  103. ;-----------------------------------------------------------------------------
  104. ; Program init complete
  105. ;-----------------------------------------------------------------------------
  106.  
  107. ; Getting the node number from the argument line..
  108.  
  109.     movem.l    (sp)+,d0/a0
  110.     move.l    DOSBase(a5),a6
  111.     move.l    a0,a3
  112.     subq.b    #2,d0            ; At least 1 char passed as argument ?
  113.     bpl.s    EASY_ArgsLenOK
  114. EASY_BadArgs:
  115.     jsr    _LVOOutput(a6)
  116.     move.l    d0,d1
  117.     lea    EASY_NoHandStart(pc),a0
  118.     move.l    a0,d2
  119.     moveq    #EASY_NoHandStartEnd-EASY_NoHandStart,d3
  120.     jsr    _LVOWrite(a6)
  121.     bra.w    EASY_Finish
  122.  
  123. EASY_ArgsLenOK:
  124.     clr.b    1(a0,d0.w)
  125.     moveq    #0,d1
  126. EASY_ParseArgs:
  127.     moveq    #0,d0
  128.     move.b    (a0)+,d0
  129.     beq.s    EASY_ArgsOK
  130.     sub.b    #48,d0
  131.     bmi.s    EASY_BadArgs    ; only digits, please..
  132.     cmp.b    #9,d0
  133.     bhi.s    EASY_BadArgs    ;  ""    ""      ""
  134.     add.b    d0,d0        ;-\
  135.     move.b    d0,d2        ;  \
  136.     add.b    d0,d0        ;   \
  137.     add.b    d0,d0        ;    \
  138.     add.b    d2,d0        ;_____\ same as "mulu #10,d0", but faster :^)
  139.     add.l    d0,d1
  140.     bra.s    EASY_ParseArgs
  141. EASY_ArgsOK:
  142.     move.l    d1,DoorPortNum(a5)
  143.     lea    FAMEDPNameTxt(pc),a0    ; Name of the FAMEDoorPort..
  144.     lea    FAMEDoorPortName(a5),a1
  145. EASY_CopyPortName:
  146.     move.b    (a0)+,(a1)+        ; ..gets copied to one new string..
  147.     bne.s    EASY_CopyPortName
  148.     subq.l    #1,a1
  149. EASY_CopyPortNumber:
  150.     move.b    (a3)+,(a1)+        ; ..together with the door port number.
  151.     bne.s    EASY_CopyPortNumber
  152.     move.l    AbsExecBase(a5),a6
  153.     jsr    _LVOCreateMsgPort(a6)
  154.     move.l    d0,DoorReplyPort(a5)
  155.     beq.w    EASY_Finish        ; No error messages possible,
  156.                     ; because the door communication
  157.                     ; wasn't established yet.
  158. EASY_DoorPortOK:
  159.     move.l    d0,a0
  160.     moveq    #0,d0
  161.     move.b    MP_SIGBIT(a0),d0    ; Get the port's signal bit
  162.     moveq    #1,d1
  163.     lsl.l    d0,d1
  164.     move.l    d1,DoorSigBits(a5)
  165.  
  166.     move.l    DoorMessage(a5),a0    ; Initialize our message structure
  167.     move.b    #NT_MESSAGE,LN_TYPE(a0)    ; Normally, exec does this line for you
  168.     move.w    #Fdom_SIZEOF,MN_LENGTH(a0)
  169.     move.l    DoorReplyPort(a5),MN_REPLYPORT(a0)
  170.  
  171.     jsr    _LVOForbid(a6)
  172.     lea    FAMEDoorPortName(a5),a1
  173.     jsr    _LVOFindPort(a6)    ; Search the DoorMsgPort for our node
  174.     move.l    d0,DoorControlPort(a5)
  175.     jsr    _LVOPermit(a6)
  176.     tst.l    DoorControlPort(a5)
  177.     beq.w    EASY_Finish        ; Error messages still not possible..
  178.  
  179. EASY_DCPortFound:
  180.  
  181. ; Now sending the MUST command MC_DoorStart to the node. Refer to the "send"
  182. ; macro for further details. The MC_DoorStart command MUST be called as the
  183. ; first of all commands.
  184. ; General:
  185. ; On negative ReturnCodes from the Node we MUST shut down the door program
  186. ; IMMEDIATELY, only sending the MUST command MC_ShutDown.
  187. ; If the ReturnCode is greater than NULL, it's up to you about what to do.
  188. ; In the case below, only FCmdRC_CommandFailed (1) should happen (started from
  189. ; CLI passing a number of a door port which really exists -> door access denied.
  190.  
  191.     moveq    #MC_DoorStart,d0
  192.     bsr    Do_SendCommand
  193.     tst.l    d0            ; This time we check it yourself,
  194.     bne.s    EASY_Finish        ; because if it fails, MC_ShutDown
  195.                     ; isn't needed anyway.
  196. ;-----------------------------------------------------------------------------
  197.  
  198.     move.l    sp,InitialStack(a5)    ; save the current stack pointer
  199.  
  200.     bsr.w    EASY_DoorCode        ; Finally: start our door code.
  201.  
  202. ;-----------------------------------------------------------------------------
  203.  
  204. EASY_Finish:
  205.     move.l    InitialStack(a5),sp    ; restore the initial stack pointer
  206.  
  207.     move.l    AbsExecBase(a5),a6
  208.     move.l    DoorReplyPort(a5),d0
  209.     beq.s    EASY_Quit4
  210.     move.l    d0,a0
  211.     jsr    _LVODeleteMsgPort(a6)
  212. EASY_Quit4:
  213.     move.l    FAMEBase(a5),d0
  214.     beq.s    EASY_Quit2
  215.     move.l    d0,a6
  216.     move.l    DoorMessage(a5),d0
  217.     beq.s    EASY_Quit3
  218.     move.l    d0,a1
  219.     jsr    _LVOFAMEFreeObject(a6)
  220.  
  221. EASY_Quit3:
  222.     move.l    a6,a1
  223.     move.l    AbsExecBase(a5),a6
  224.     jsr    _LVOCloseLibrary(a6)
  225.  
  226. EASY_Quit2:
  227.     move.l    DOSBase(a5),d0
  228.     beq.s    EASY_Quit1
  229.     move.l    d0,a1
  230.     jsr    _LVOCloseLibrary(a6)
  231. EASY_Quit1:
  232.     move.b    ReturnCode(a5),d7
  233.     move.l    a5,a1            ; No NULL check needed here.
  234.     jsr    _LVOFreeVec(a6)
  235. EASY_Quit:
  236.     moveq    #0,d0
  237.     add.b    d7,d0
  238.     rts                ; The end.
  239.  
  240. ;-----------------------------------------------------------------------------
  241. ; Several often used routines
  242. ;-----------------------------------------------------------------------------
  243.  
  244. ; Next: the code belonging to the send macro function. The error code
  245. ; gets checked here and on error codes <>0, ByeMessage is set to a decent
  246. ; error text. Then the door shuts down.
  247.  
  248. SendDoorCommand:
  249.     bsr.w    Do_SendCommand
  250.     tst.l    d0
  251.     bne.s    SDC_Abort
  252.     rts
  253. SDC_Abort:
  254.     bmi.s    SDC_NegativeError
  255.  
  256.     subq.l    #1,d0
  257.     bne.s    SDC_Abort2
  258.     lea    EASY_CommandExecutionError(pc),a0
  259.     bra.s    SDC_SetError
  260. SDC_Abort2:
  261.     subq.l    #1,d0
  262.     bne.s    SDC_Abort3
  263. SDC_UnknownCmd:
  264.     lea    EASY_CommandNotImplemented(pc),a0
  265.     bra.s    SDC_SetError
  266. SDC_Abort3:
  267.     subq.l    #1,d0
  268.     bne.s    SDC_Abort4
  269.     lea    EASY_CommandDenied(pc),a0
  270.     bra.s    SDC_SetError
  271. SDC_Abort4:
  272.     bra.s    SDC_UnknownCmd        ; same error text.
  273.  
  274. SDC_NegativeError:
  275.     addq.l    #1,d0
  276.     bne.s    SDC_Abort5
  277.     lea    EASY_DoorAbortRequested(pc),a0
  278.     bra.s    SDC_SetError
  279. SDC_Abort5:
  280.     addq.l    #1,d0
  281.     bne.s    SDC_Abort6
  282.     lea    EASY_CarrierLost(pc),a0
  283.     bra.s    SDC_SetError
  284. SDC_Abort6:
  285.     lea    EASY_FatalError(pc),a0
  286.  
  287. SDC_SetError:
  288.     move.l    a0,ByeMessage(a5)
  289.     bra    Abort
  290.  
  291. Do_SendCommand:
  292.     move.l    DoorMessage(a5),a0
  293.     move.l    d0,Fdom_Command(a0)    ; Set door command
  294.  
  295.     move.l    a6,-(sp)
  296.     Move.l    AbsExecBase(a5),a6
  297.  
  298.     jsr    _LVOForbid(a6)
  299.     move.l    DoorControlPort(a5),a0
  300.     move.l    DoorMessage(a5),a1
  301.     jsr    _LVOPutMsg(a6)        ; Send the command to our node
  302.     jsr    _LVOPermit(a6)
  303.     moveq    #0,d7
  304. DSC_Wait:
  305.     move.l    DoorSigBits(a5),d0
  306.     jsr    _LVOWait(a6)        ; Wait for a message
  307.  
  308.  
  309.  
  310.     ; insert additional Signal reactions here
  311.  
  312.  
  313.  
  314.     move.l    DoorReplyPort(a5),a0
  315.     jsr    _LVOGetMsg(a6)        ; Get the message back
  316.     tst.l    d0
  317.     beq.s    DSC_Wait        ; There was no message.
  318.  
  319.     move.l    DoorMessage(a5),a0
  320.     move.l    Fdom_ReturnCode(a0),d0    ; Put the ReturnCode to d0 for
  321. DSC_Quit:                ; easier result checking.
  322.     move.l    (sp)+,a6        ; a0 contains the DoorMessage
  323.     rts                ; structure on exit.
  324.  
  325. ;-----------------------------------------------------------------------------
  326. ; The following routines can be used to copy a String FROM or TO
  327. ; the Fdom_IOString field. But these routines became a bit obsolete,
  328. ; because the newer AR_SendString commands allow sending strings from any
  329. ; APTR. If you find it useful, use it. The routines are called like this:
  330. ;
  331. ;     Move.l    AdressOfText,a0        ; Pass the APTR to SetIOString
  332. ;     bsr    SetIOString
  333. ;-----------------------------------------------------------------------------
  334.  
  335. GetIOString:
  336.     move.l    DoorMessage(a5),a1
  337.     lea    Fdom_IOString(a1),a1
  338.     move.w    #202-1,d0        ; Make sure that we don't copy more
  339. GIO_Loop:                ; than 202 bytes..
  340.     move.b    (a1)+,(a0)+
  341.     beq.s    GIO_End
  342.     dbra    d0,GIO_Loop
  343. GIO_End:
  344.     rts
  345.  
  346. ;-----------------------------------------------------------------------------
  347.  
  348. SetIOString:
  349.     move.l    DoorMessage(a5),a1
  350.     lea    Fdom_IOString(a1),a1
  351.     move.w    #202-1,d0        ; Make sure that we don't copy more
  352. SIO_Loop:                ; than 202 bytes..
  353.     move.b    (a0)+,(a1)+
  354.     beq.s    SIO_End
  355.     dbra    d0,SIO_Loop
  356. SIO_End:
  357.     rts
  358.  
  359. ;-----------------------------------------------------------------------------
  360. ; Data area
  361. ;-----------------------------------------------------------------------------
  362.  
  363. EASY_MyDataSize:    dc.l    MyData_SIZEOF ; Size of our program data area
  364.  
  365. EASY_CarrierLost:
  366.     dc.b    13,10,"CARRIER LOST ! Door shut down."
  367.     dc.b    13,10,13,10,0
  368.  
  369. EASY_CommandDenied:
  370.     dc.b    13,10,"Sorry, but this door can't execute all of it's door"
  371.     dc.b    13,10,"commands, because your SysOp has denied access to"
  372.     dc.b    13,10,"some of 'em."
  373.     dc.b    13,10,"Try making him/her read the door documentations.. :^)"
  374.     dc.b    13,10,13,10,0
  375.  
  376. EASY_CommandExecutionError:
  377.     dc.b    13,10,"Sorry, but FAME reported an error during the execution"
  378.     dc.b    13,10,"of a door command. Tell your SysOp about the problem."
  379.     dc.b    13,10,13,10,0
  380.  
  381. EASY_CommandNotImplemented:
  382.     dc.b    13,10,"Sorry, but this door wants to use a door command"
  383.     dc.b    13,10,"which isn't supported by the current FAME version."
  384.     dc.b    13,10,"Seems that you should install a newer version of"
  385.     dc.b    13,10,"FAME BBS to run this door.."
  386.     dc.b    13,10,13,10,0
  387.  
  388. EASY_DoorAbortRequested
  389.     dc.b    13,10,"Sorry, but your sysop has just shut down the door."
  390.     dc.b    13,10,13,10,0
  391.  
  392. EASY_FatalError:
  393.     dc.b    13,10,"FATAL ERROR ! A door command couldn't be executed,"
  394.     dc.b    13,10,"because an unknown fatal error occured."
  395.     dc.b    13,10,"Please tell your SysOp about."
  396.     dc.b    13,10,13,10,0
  397.  
  398. EASY_NoHandStart:    dc.b    10,"Sorry, this is a FAME BBS door program.",10
  399.             dc.b    "It can only be started from FAME itself.",10,10
  400. EASY_NoHandStartEnd:
  401.  
  402. DosName:    dc.b    "dos.library",0
  403.  
  404. FAMEDPNameTxt:    dc.b    "FAMEDoorPort",0    ; That's it's name. :^)
  405.  
  406. FAMEName    dc.b    "FAME.library",0
  407.  
  408.         cnop    0,4
  409.  
  410. EASY_DoorCode:
  411.  
  412.